<?php
require_once 'ApibaseController.php';

/**
 * ASメンバーズネット物件リクエスト問い合わせAPI<br />
 *
 * ASメンバーズネット物件リクエスト問い合わせAPI
 *
 * @package apamanshop
 * @author ushijima
 * @copyright コピーライト(要確認)
 */
class Inquiry_ApiasmemberrequestController extends Inquiry_ApibaseController
{

	//店舗情報
	private $shoplist;

	/**
	 * ASメンバーズネット物件リクエスト問合せAPIアクション
	 *
	 * @access public
	 * @return void
	 */
	public function indexAction()
	{

		// 変数初期化処理 start
		//都道府県コード
		$strPrefCd = $this->_params['PrefCd'];
		//市区町村コード
		$strCityCd = $this->_params['CityCd'];
		//町コード
		$strTownCd = $this->_params['TownCd'];
		//沿線コード
		$strRailCd = $this->_params['RailCd'];
		//駅コード
		$strStCd = $this->_params['StCd'];

		//検索区分
		$strSrhKbn = $this->_params['SrhKbn'];
		$strSrhType = $this->_params['SrhType'];

		//設定しなおし
		$strCondDsp = str_replace(" ",", ",$this->_params['condDsp']);

		//賃料
		$inttinryo1 = $this->_params['tinryo1'];
		$inttinryo2 = $this->_params['tinryo2'];
		$strtinryo_jouken2 = $this->_params['tinryo_jouken2'];
		$strtyusyajyo_komi = $this->_params['tyusyajyo_komi'];
		$strmeyasu_tinryo = $this->_params['meyasu_tinryo'];
		$strfreerent = $this->_params['freerent'];
		$strshikireizero = $this->_params['shikireizero'];
		$strshikikin_nashi = $this->_params['shikikin_nashi'];
		$strreikin_nashi = $this->_params['reikin_nashi'];
		$strshataku_koujyo = $this->_params['shataku_koujyo'];
		$strheyawari = $this->_params['heyawari'];
		//初期費用
		$strsyokihiyo = $this->_params['syokihiyo'];
		//建物種別
		$strsyubetu1 = $this->_params['syubetu1'];
		$strsyubetu2 = $this->_params['syubetu2'];
		$strsyubetu3 = $this->_params['syubetu3'];
		$strsyubetu4 = $this->_params['syubetu4'];
		$strsyubetu5 = $this->_params['syubetu5'];
		//駅徒歩
		$intekitoho = $this->_params['ekitoho'];
		$strbas_riyou = $this->_params['bas_riyou'];
		//占有面積
		$strsenyu1 = $this->_params['senyu1'];
		$strsenyu2 = $this->_params['senyu2'];
		//間取り
		$strmadori10 = $this->_params['madori10'];
		$strmadori11 = $this->_params['madori11'];
		$strmadori12 = $this->_params['madori12'];
		$strmadori14 = $this->_params['madori14'];
		$strmadori21 = $this->_params['madori21'];
		$strmadori22 = $this->_params['madori22'];
		$strmadori24 = $this->_params['madori24'];
		$strmadori31 = $this->_params['madori31'];
		$strmadori32 = $this->_params['madori32'];
		$strmadori34 = $this->_params['madori34'];
		$strmadori41 = $this->_params['madori41'];
		$strmadori42 = $this->_params['madori42'];
		$strmadori44 = $this->_params['madori44'];
		$strmadori51 = $this->_params['madori51'];

		//築年数
		$intbuilt = $this->_params['built'];
		//情報の新しさ
		$strjyohou = $this->_params['jyohou'];

		//希望日
		$strnyukyoM = $this->_params['nyukyoM'];
		$strnyukyoD = $this->_params['nyukyoD'];
		$strnyukyoBiko = $this->_params['nyukyoBiko'];

		//内見
		$strnaikenM = $this->_params['naikenM'];
		$strnaikenD = $this->_params['naikenD'];

		//個人情報ﾊﾟﾗﾒｰﾀ
		$strNameSei = $this->_params['NameSei'];
		$strNameMei = $this->_params['NameMei'];
		$strMail = $this->_params['Mail'];
		$strTel = $this->_params['Tel'];
		$strNeedTimeKbn = $this->_params['NeedTimeKbn'];
		$strFax = $this->_params['Fax'];
		$strInqryContents = $this->_params['Comment'];

		$strKeiyaku = $this->_params['keiyakutype'];
		$intChushajoDaisu = $this->_params['chushajoDaisu'];
		$strUserComName = $this->_params['UserComName'];

		//店舗コード配列化
		$add_params['arrSelShop'] = $this->_params['SelShop'];

		//送信時刻
		$strTimeStr = $this->_params['TimeStr'];

		if($strPrefCd == "" && $strCityCd == "" && $strStCd == "") {
			//予期せぬエラー
			$result = 0;
		} else {

			//-----契約形態(DspKeiyaku)
			if ($strKeiyaku == "1") {
				$add_params['DspKeiyaku'] = "法人";
			}else{
				$add_params['DspKeiyaku'] = "個人";
			}

			//-----駅徒歩(DspEkitoho)
			if ($intekitoho == "0") {
				$add_params['DspEkitoho'] = "指定なし";
			} else {
				$add_params['DspEkitoho'] = $intekitoho . "分以内";
			}
			// バス利用可
			if ($strbas_riyou == "on") {
				$add_params['DspEkitoho'] = $add_params['DspEkitoho'] . " バス利用可";
			}

			//-----賃料（DspTinryo1,DspTinryo2）
			if ($inttinryo1 == "0"|| $inttinryo1 == "下限なし") {
				$add_params['DspTinryo1'] = "下限なし";
				$this->_params['tinryo1'] = 0;
			} else {
				$add_params['DspTinryo1'] = $inttinryo1/10000 . "万";
			}

			if ($inttinryo2 == "9999999" || $inttinryo2 == "上限なし") {
				$add_params['DspTinryo2'] = "上限なし";
				$this->_params['tinryo2'] = 9999999;
			} else {
				$add_params['DspTinryo2'] = $inttinryo2/10000 . "万";
			}
			//-----めやす賃料
			if ($strmeyasu_tinryo == "meyasu") {
				$add_params['DspTinryo1'] = "めやす賃料：" . $add_params['DspTinryo1'];
			}

			//-----問合わせ内容
			$add_params['InqryContents'] = $strInqryContents;

			//-----間取り(DspMadori)
			if (($strmadori10 != "on" && $strmadori11 != "on" && $strmadori12 != "on" && $strmadori14 != "on" && $strmadori21 != "on" && $strmadori22 != "on" && $strmadori24 != "on" && $strmadori31 != "on" && $strmadori32 != "on" && $strmadori34 != "on" && $strmadori41 != "on" && $strmadori42 != "on" && $strmadori44 != "on" && $strmadori51 != "on") ||
			   ($strmadori10 == "on" && $strmadori11 == "on" && $strmadori12 == "on" && $strmadori14 == "on" && $strmadori21 == "on" && $strmadori22 == "on" && $strmadori24 == "on" && $strmadori31 == "on" && $strmadori32 == "on" && $strmadori34 == "on" && $strmadori41 == "on" && $strmadori42 == "on" && $strmadori44 == "on" && $strmadori51 == "on") )
			{
				$add_params['DspMadori'] = "[全て]";

			} else {

				if ($strmadori10 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1R]";
				}
				if ($strmadori11 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1K]";
				}
				if ($strmadori12 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1DK(+S)]";
				}
				if ($strmadori14 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[1LDK(+S)]";
				}
				if ($strmadori21 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[2K]";
				}
				if ($strmadori22 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[2DK(+S)]";
				}
				if ($strmadori24 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[2LDK(+S)]";
				}
				if ($strmadori31 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[3K]";
				}
				if ($strmadori32 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[3DK(+S)]";
				}
				if ($strmadori34 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[3LDK(+S)]";
				}
				if ($strmadori41 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[4K]";
				}
				if ($strmadori42 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[4DK(+S)]";
				}
				if ($strmadori44 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[4LDK(+S)]";
				}
				if ($strmadori51 == "on") {
					$add_params['DspMadori'] = $add_params['DspMadori'] . "[5K～]";
				}
			}

			//-----築年数
			if ($intbuilt == ""){
				$intbuilt = 0;
				$this->_params['built'] = 0;
			}
			if ($intbuilt == "0") {
				$add_params['DspBuilt'] = "指定なし";
			}else if ($intbuilt == "1") {
				$add_params['DspBuilt'] = "新築";
			} else {
				$add_params['DspBuilt'] = $intbuilt . "年以内";
			}

			//-----専有面積 (0以外だったら値を入れる）
			if ($strsenyu1 != "1" || $strsenyu1 != "下限なし") {
				$add_params['DspSenyu']  = $strsenyu1 . "ｍ2以上" . "～";
			}

			if ($strsenyu2 != "99999" || $strsenyu2 != "上限なし") {
				$add_params['DspSenyu']  = $add_params['DspSenyu'] . $strsenyu2 . "ｍ2以内";
			}

			if (($strsenyu1 == "1") && ($strsenyu2 == "99999") || ($strsenyu1 == "下限なし") && ($strsenyu2 == "上限なし")) {
				$add_params['DspSenyu']  = "限度なし";
			}
			if ($strsenyu1 == "下限なし"){
				$this->_params['senyu1'] = 1;
			}
			if ($strsenyu2 == "上限なし"){
				$this->_params['senyu2'] = 99999;
			}


			//-----建物種別
			if (($strsyubetu1 == "on" && $strsyubetu2 == "on" && $strsyubetu3 == "on" && $strsyubetu4 == "on" && $strsyubetu5 == "on") ||
				($strsyubetu1 == "" && $strsyubetu2 == "" && $strsyubetu3 == "" && $strsyubetu4 == "" && $strsyubetu5 == ""))
			{
				$add_params['DspSyubetu'] = "[全て]";

			} else {

				if ($strsyubetu1 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[賃貸アパート]";
				}
				if ($strsyubetu2 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[賃貸マンション]";
				}
				if ($strsyubetu3 == "on") {
//					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[賃貸一戸建て・借家・テラスハウス]";
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[戸建て・テラスハウス]";
				}
				if ($strsyubetu4 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[貸店舗・賃貸事務所]";
				}
				if ($strsyubetu5 == "on") {
					$add_params['DspSyubetu'] = $add_params['DspSyubetu'] . "[駐車場]";
				}
			}

			//（管理費・共益費込み）
			if ($strtinryo_jouken2 == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[管理費・共益費込み]";
			}
			//（駐車場代込み）
			if ($strtyusyajyo_komi == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[駐車場代込み]";
			}
			//（敷金礼金０）
			// ----- UPDATE Start 2011/06/20 ダブルゼロ分割対応 SS Ishii-n -----
			//if ($strshikikin_nashi == "on" && $strreikin_nashi == "on"){
			if (($strshikikin_nashi == "on" && $strreikin_nashi == "on") || ($strsyokihiyo != "" && $strsyokihiyo == "w0")){
			// ----- UPDATE End   2011/06/20 ダブルゼロ分割対応 SS Ishii-n -----
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[敷金・礼金0]";
			}else if ($strshikikin_nashi == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[敷金0]";
			}else if ($strreikin_nashi == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[礼金0]";
			}
			//（フリーレント）
			if ($strfreerent == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[ﾌﾘｰﾚﾝﾄ]";
			}
			//（部屋割）
			if ($strHeyaWari == "on") {
				$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[部屋割]";
			}
			//（初期費用）
			if ($strsyokihiyo != "" && $strsyokihiyo != "0" && $strsyokihiyo <> "w0") {
				if ($strsyokihiyo == "99") {
					$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[初期費用0円]";
				} else {
					$add_params['HTinryoJkn'] = $add_params['HTinryoJkn'] . "[初期費用".$strsyokihiyo."万円]";
				}
			}

			// 希望日
			if ($strnyukyoM == "0" || $strnyukyoM == "" || $strnyukyoD == "0" || $strnyukyoD == ""){
				$add_params['DspNyukyo'] = "指定なし";
			}else{
				$add_params['DspNyukyo'] = $strnyukyoM . "月" . $strnyukyoD . "日";
			}
			if ($strnyukyoBiko != ""){
				$add_params['DspNyukyoBiko'] = $strnyukyoBiko;
			}

			// 内見
			if ($strnaikenM == "0" || $strnaikenM == "" || $strnaikenD == "0" || $strnaikenD == ""){
				$add_params['DspNaiken'] = "指定なし";
			}else{
				$add_params['DspNaiken'] = $strnaikenM . "月" . $strnaikenD . "日";
			}

			//駐車場台数
			if ($intChushajoDaisu != ""){
				$add_params['DspChushajoDaisu'] = $intChushajoDaisu . "台";
			}

			//--------------------------------------------------------
			//= 選択ﾒﾆｭｰ別変数初期化取得処理
			//--------------------------------------------------------

			switch($this->_params['SrhType']) {

				//@ 住所を選択する(eki)
				Case "1":

					$add_params['DspKibouToshi'] = $strCondDsp;
					$add_params['DspKibouEnsen'] = "";
					$add_params['DspKibouEki'] = "";
					break;

				//@ 沿線を選択する(pref, skchsn)
				Case "2";

					$add_params['DspKibouToshi'] = "";
					$add_params['DspKibouEnsen'] = $strCondDsp;
					$add_params['DspKibouEki'] = "";
					break;

			}

		//--------------------------------------------------------
		//= 表示情報設定処理
		//--------------------------------------------------------

			//@ 希望連絡手段(表示)
			$strCntctWayStr = "";
			//希望連絡(ﾒｰﾙ)が設定されている場合
			if ($strCntctWayMail == "1") {
				$strCntctWayStr = $strCntctWayStr . "メール，";
			}
			//希望連絡(TEL)が設定されている場合
			if ($strCntctWayTel == "1") {
				$strCntctWayStr = $strCntctWayStr . "ＴＥＬ，";
			}
			//希望連絡(FAX)が設定されている場合
			if ($strCntctWayFax == "1") {
				$strCntctWayStr = $strCntctWayStr . "ＦＡＸ，";
			}
			if ($strCntctWayStr != "") {
				$strCntctWayStr = rtrim($strCntctWayStr,",");
			}
            $this->params['CntctWayStr'] = $strCntctWayStr;

			//@ 希望連絡手段CD
			$strCntctWayCd = "";
			//希望連絡(TEL)が設定されている場合
			if ($strCntctWayTel == "1") {
				$strCntctWayCd = $strCntctWayCd . "1";
			} else {
				$strCntctWayCd = $strCntctWayCd . "0";
			}
			//希望連絡(ﾒｰﾙ)が設定されている場合
			if ($strCntctWayMail == "1") {
				$strCntctWayCd = $strCntctWayCd . "1";
			} else {
				$strCntctWayCd = $strCntctWayCd . "0";
			}
			//希望連絡(FAX)が設定されている場合
			if ($strCntctWayFax == "1") {
				$strCntctWayCd = $strCntctWayCd . "1";
			} else {
				$strCntctWayCd = $strCntctWayCd . "0";
			}

			//希望時間
			$arrNeedTimeKbn = Array("希望なし","10時以前","10時～12時","12時～14時","14時～16時","16時～18時","18時以降");

			if ($strNeedTimeKbn != "") {
				$add_params['DspstrNeedTimeKbn'] = $arrNeedTimeKbn[$strNeedTimeKbn];
			}

			//--- メール判定 ---
			$this->setSendMailFlag($this->_params['Mail']);

			// ﾛｸﾞ情報格納処理 *****************************************
			$resApi = array();
			try {
				// モデルの呼び出し
				$this->_model = new Inquiry_Model_Apiinquiry();

				//トランザクション開始
				$db = $this->_model->getDbConnection();

				//トランザクション開始
				$this->_model->startTransaction($db);

				//企業情報取得
				$Complist = $this->_model->getInqCompanyQry($this->_params);

				//（仲介手数料）
				if ($strshataku_koujyo == "on") {
					$add_params['HTinryoJkn'] .= "[仲介手数料" . (100-$Complist[0]['M86_SHATAKU_KOUJYORITSU'])/100*1.05 . "ヶ月分以下]";
				}
				$add_params['strComName'] = $Complist[0]['M86_COMPANY_NAME'];
				$add_params['ComName'] = $Complist[0]['M86_COMPANY_NAME'];
				$add_params['TensouMail'] = $Complist[0]['M86_TENSOU_MAIL'];

				//こだわり条件文字列
				$add_params['KodawariData'] = $this->setKodawariData($this->_model->GetKodawari());

				//キャンペーン 2012/02/17 Add H.Imamura
				if (!is_null($this->_params['campaign']) && !empty($this->_params['campaign'])) {
					$campaign_cd = array();
					if (is_array($this->_params['campaign'])) {
						$campaign_cd = $this->_params['campaign'];
					} else {
						$campaign_cd[] = $this->_params['campaign'];
					}
					$this->_model_bukken = new Inquiry_Model_Apibukken();
					$add_params['KodawariData']['HKodawari'] .= $this->setCampaignData($this->_model_bukken->GetCampaignList("1,4", $campaign_cd));
				}

				//問合わせID生成
				$strToiawaseId = strval($this->GetTimeString()) . strval($this->GetToiawaseSEQ($db));

				$add_params['InqNo'] = $strToiawaseId;
				$add_params['ComGenruFlg'] = $Complist[0]['M86_GENRU_FLAG'];
				$add_params['Seqcount'] = 0;
				//問合せﾕｰｻﾞ情報格納ｸｴﾘ取得処理
				array_push($resApi,$this->_model->insInqHoujinLog($db,$this->_params,$add_params));
				// W25TOIAWASE_USER_LOG
				if($this->isLogIns() == true) {
					array_push($resApi,$this->_model->insInqUserLog3($db,$this->_params,$add_params));
				}

				// W33REQUEST_AREA_LOG
				$add_params['targetPrefCd'] = '';
				$add_params['targetCityCd'] = '';
				$add_params['targetTownCd'] = '';
				$add_params['targetRailCd'] = '';
				$add_params['targetStCd']   = '';
				if($strSrhType == "1") {
					if($strTownCd != "") {
						foreach($strTownCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetPrefCd'] = mb_substr($val,0,2);
							$add_params['targetCityCd'] = mb_substr($val,2,3);
							$add_params['targetTownCd'] = mb_substr($val,5,3);
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}else if($strCityCd != "") {
						foreach($strCityCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetPrefCd'] = mb_substr($val,0,2);
							$add_params['targetCityCd'] = mb_substr($val,2,3);
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}else if ($strPrefCd != ""){
						foreach($strPrefCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetPrefCd'] = mb_substr($val,0,2);
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}
				}else if($strSrhType == "2") {
					if($strStCd != "") {
						foreach($strStCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetRailCd'] = mb_substr($val,0,4);
							$add_params['targetStCd'] = $val;
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
													}
					}else if($strRailCd != "") {
						foreach($strRailCd as $key => $val){
							//ﾘｸｴｽﾄｴﾘｱ情報格納ｸｴﾘ取得処理
							$add_params['Seqcount'] += 1;
							$add_params['targetRailCd'] = $val;
							$resApi = $this->arraySum($resApi,$this->_model->InsRequestAreaLog($db,$this->_params,$add_params));
						}
					}
				}

				// W21PAGE_VIEW_LOG
				$add_params['ViewKbn']   = "4";
				$add_params['OrgHeyaCd'] = "";
				$this->_params['ShopCd'] = " ";
				if($this->isLogIns() == true) {
					array_push($resApi,$this->_model->pageViewLog($db,$this->_params,$add_params));
				}

				// ﾒｰﾙ送信処理 ********************************************
				$result =  $this->SendMailMain($strMail,$add_params);

				if($result != "0"){
					 $this->raiseError('メール送信エラー');
				}

				__log_debug(__FILE__, __LINE__, __METHOD__, "コミットします");
				$this->_model->commitTransaction($db);
				$db->closeConnection();

				$result = 1;

			} catch (Exception $e) {
				__log_debug(__FILE__, __LINE__, __METHOD__, "ロールバックします");
				$this->_model->rollbackTransaction($db);
				$db->closeConnection();
				$result = 0;
			}
		}
		// 返却データ作成
		$resResult = array('api_result' => array('result' => $result,'res_detail' => $resApi));
		// 返却処理
		$this->_api_data = $resResult;
		$this->display();

	}

	//メール送信制御
	private function SendMailMain($mail,$addinfo) {
		// ｽﾃｰﾀｽ初期化

		// 本部へのメール送信
		$officeResult = $this->SendMailOffice($addinfo);

		// ユーザへメール送信
		if ($mail != "") {
			$userResult = $this->SendMailUser($mail,$addinfo);
		}

		$result = 1;
		//メール送信チェック
		if ( $userResult == 0 || $shopResult == 0 || $officeResult == 0) {
			$result = 0;
		}
		return $result;
	}

	// 問い合わせユーザへのメール送信
	private function SendMailUser($mail,$addinfo) {

		// from(送信元)、to（あて先)
		$strMailTo = array($mail => "");							//送信先ﾒｰﾙｱﾄﾞﾚｽ
		$strMailFrom = array(Apm_Config_Mail::MAIL_AS => "");		//送信元ﾒｰﾙｱﾄﾞﾚｽ
		// メール転送処理
		$strMailCc = array();
		if (!empty($addinfo['TensouMail'])) {
			$tensouMail = explode(",", $addinfo['TensouMail']);
			foreach ($tensouMail as $val) {
				$strMailCc[$val] = "";
			}
		}

		// メール本文に必要なパラメータ
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_SUBJECT_KEY] =  "［アパマンショップ］物件リクエスト登録のご確認　(" . $addinfo['strComName'] . "様)";
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = $strMailTo;
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_FROM_KEY] = $strMailFrom;

		//if($this->isSendShop() == true && !empty($strMailCc)) {		// ジャッジメールでなければCC追加
		if(!empty($strMailCc)) {		// ジャッジメールでもCC追加
			// ※※DB登録されている転送先へメールが飛ぶので注意する事※※
			$mail_params[Apm_Otheritems::SEND_MAIL_EX_CC_KEY] = $strMailCc;
		}
		// ﾒｰﾙ送信処理
		// 2012.12.27 92.ゲイングループ(133)の場合、テンプレートを変更
		if ($this->_params['ComId'] == '92') {
			$result = $this->sendToiawaseMailJudge("MailAsmemberRequestUser".$this->_params['ComId'].".tpl", array_merge($this->_params,$addinfo), $mail_params, 3);
		} else {
			$result = $this->sendToiawaseMailJudge("MailAsmemberRequestUser.tpl", array_merge($this->_params,$addinfo), $mail_params, 3);
		}

		//// ﾒｰﾙ送信処理
		//if($this->isSendUser() == true) {
		//	// 店舗ジャッジメールでなければCC追加 => ジャッジメールでもCC追加(2012/02/24update)
		//	// ※※DB登録されている転送先へメールが飛ぶので注意する事※※
		//	//if($this->isSendShop() == true && !empty($strMailCc)) {
		//	if(!empty($strMailCc)) {
		//		$mail_params[Apm_Otheritems::SEND_MAIL_EX_CC_KEY] = $strMailCc;
		//	}
		//	// ﾒｰﾙ送信処理
		//	$result = $this->sendToiawaseMail("MailAsmemberRequestUser.tpl",array_merge($this->_params,$addinfo), $mail_params);
		//}

		return $result;
	}

	// 本部のメール送信
	private function SendMailOffice($addinfo) {

		$strMailTo =   array(Apm_Config_Mail::MAIL_AS => "");		//送信先ﾒｰﾙｱﾄﾞﾚｽ
		$strMailFrom = array(Apm_Config_Mail::MAIL_NETWORK => "");	//送信元ﾒｰﾙｱﾄﾞﾚｽ

		// 2012.12.27 92.ゲイングループ(133)の場合、送信先を「hna@gainer.co.jp」に変更する
		if ($this->_params['ComId'] == '92') {
			$strMailTo = array("hna@gainer.co.jp" => "");
		}

		//@ 送信先ﾒｰﾙｱﾄﾞﾚｽ
		// 本文の設定
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_SUBJECT_KEY] = "◆リクエストメール◆ 住宅斡旋依頼" . "　(". $addinfo['strComName'] . "様)";
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = $strMailTo;
		$mail_params[Apm_Otheritems::SEND_MAIL_EX_FROM_KEY] = $strMailFrom;

		// テンプレート設定
		$request_template = APPLICATION_PATH . '/modules/inquiry/views/mail/MailAsmemberRequestBody.tpl';
		$addinfo['request_body'] = $this->getApmHelper($request_template)->getBlock(array_merge($this->_params,$addinfo));

		// ﾒｰﾙ送信処理
		$result = $this->sendToiawaseMailJudge("MailAsmemberRequest".$this->_params['ComId'].".tpl", array_merge($this->_params,$addinfo), $mail_params, 1);
		//if($this->isSendHonbu() == true) {
		//	// ﾒｰﾙ送信処理
		//	$result = $this->sendToiawaseMail("MailAsmemberRequest" . $this->_params['ComId'] . ".tpl",array_merge($this->_params,$addinfo), $mail_params);
		//}else if($this->getReplaceHonbuMail() != "") {
		//	$mail_params[Apm_Otheritems::SEND_MAIL_EX_TO_KEY] = array($this->getReplaceHonbuMail() => "");
		//	// ﾒｰﾙ送信処理
		//	$result = $this->sendToiawaseMail("MailAsmemberRequest" . $this->_params['ComId'] . ".tpl",array_merge($this->_params,$addinfo), $mail_params);
		//}

		return $result;
	}

	/**
	 * 各種条件文字列化
	 * @param unknown_type $reslist
	 */
	private function setKodawariData($reslist){
		$max = 0;
		foreach($reslist as $key => $value){
			if($value['W74_KODAWARI_ID'] > $max){
				$max = $value['W74_KODAWARI_ID'];
			}
		}

		$temp['HKodawari'] = "";
		$temp['vKodawari'] = str_repeat('0',$max);
		//こだわり条件Text&DB
		foreach($reslist as $key => $value){
			if($this->_params['kodawari' . $value['W74_KODAWARI_ID'] ] != ""){
				$temp['HKodawari'] .= "[" . $value['W74_KODAWARI_NAME']  . "]";
				$temp['vKodawari'] = $this->repKodawari($temp['vKodawari'],$value['W74_KODAWARI_ID'],$max);
			}
		}

		return $temp;
	}

	/**
	 * こだわり文字列置換処理
	 * @param unknown_type $value 置換文字列値
	 * @param unknown_type $tarIdx 変換位置
	 * @param unknown_type $max 最大桁数
	 */
	private function repKodawari($value,$tarIdx,$max){

		if (($max - $tarIdx) == 0)
		{
			return (mb_substr($value,0,$tarIdx -1) . "1");
		}
		else
		{
			return (mb_substr($value,0,$tarIdx -1) . "1" . mb_substr($value,-1 * ($max - $tarIdx)));
		}

	}

	/**
	 * キャンペーン条件文字列化
	 * @param unknown_type $reslist
	 */
	private function setCampaignData($reslist){
		
		$temp = "";
		foreach($reslist as $key => $value){
			$temp .= "[" . $value['M94_CAMPAIGN_NAME']  . "]";
		}

		return $temp;
	}

}
?>
